package cn.neusoft.xmlaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


public class Aop {


    //在业务代码之前执行  前置通知
    public void before(){
        System.out.println("前置通知");
    }

    //在业务代码之后执行   后置通知
    public void after(){
        System.out.println("后置通知");
    }

    public void afterThrowing(){
        System.out.println("异常后通知");
    }

    public void afterReturning(){
        System.out.println("返回后通知");
    }


    public Object around(ProceedingJoinPoint pjp){
        System.out.println("**"+pjp);
        System.out.println("开启事务");
        try{
            Object result = pjp.proceed();
            System.out.println("提交事务");
            return result;
        }catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("回滚事务");
            return null;
        } finally {
            System.out.println("关闭事务");
        }
    }

}
